﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Web.Cms.PropertyTypes;
using Proggy.Web.Cms.AppHelpers;

namespace Proggy.Web.Cms.Core.Configuration.ConfigObjects
{
    /// <summary>
    /// Config for drag and drop
    /// </summary>
    public class DragAndDropConfigObject : PropertyTypeConfigObjectBase
    {
        /// <summary>
        /// Height of drag and drop rendered display (default=30)
        /// </summary>
        public decimal HeightEm
        {
            get { return this._heightEm; }
            set { this._heightEm = value; }
        }

        /// <summary>
        /// Width of drag and drop rendered display (default=60)
        /// </summary>
        public decimal WidthEm
        {
            get { return this._widthEm; }
            set { this._widthEm = value; }
        }

        // backing fields
        private decimal _heightEm = 30;
        private decimal _widthEm = 60;

        // readonly
        public decimal HeightAdjustEm { get { return 1.2m; } }
        public decimal WidthAdjustEm { get { return 1.2m; } }

        /// <summary>
        /// The stylesheets for the inner area
        /// </summary>
        public string[] Stylesheets { get; set; }

        /// <summary>
        /// The id of the area (in order to style it)
        /// </summary>
        public string AreaId
        {
            get
            {
                if (this._areaId == null)
                {
                    this._areaId = "dand" + DateTime.Now.ToFileTimeUtc() + "dand";
                }

                return this._areaId;
            }
        }

        // backing field
        private string _areaId;

        /// <summary>
        /// The class of the area (in order to style it)
        /// </summary>
        public string AreaClass { get; set; }

        /// <summary>
        /// Parts allowed to be used in this editor (comma separated "name" value from web config)
        /// </summary>
        public string AllowedParts
        {
            get {
                if (this._allowedParts == null) {
                    this._allowedParts = 
                        string.Join(",",
                            DragAndDropManager
                            .DragAndDropPartsCache
                            .OrderBy(x => x.FriendlyName)
                            .Select(x=>x.Name)
                            .ToList());
                }

                //
                return this._allowedParts;
            }
            set { this._allowedParts = value; }
        }

        // backing field
        private string _allowedParts;

    }
}
